# -*- coding: utf-8 -*-
# @Time     : 2021/12/1 15:40
# @Author   : wljess
# @File     : 守护线程.py
# @Describe : 
# @Software : PyCharm

import time
from threading import Thread


def task1():
    while True:
        time.sleep(0.5)
        print("task1 is running")


def task2():
    time.sleep(2.1)
    print("task2 is running")


t1 = Thread(target=task1)
t2 = Thread(target=task2)
t1.daemon = True
t1.start()
t2.start()

print("main threading ending...")
'''
执行结果分析：
main threading ending...
task1 is running
task1 is running
task1 is running
task1 is running
task2 is running
守护线程一直等到所有的非守护线程都结束之后才结束。不仅守护主线程，还守护其它非守护子线程。
'''
